
#include "CBackgroundScreen.h"

void CBackgroundScreen::load(CGraphics *gl)
{
    gl->loadTexture( QString::fromStdWString(L"./img/tex0.jpg"), textures[0] );
    gl->loadTexture( QString::fromStdWString(L"./img/tex1.png"), textures[1] );
    gl->loadTexture( QString::fromStdWString(L"./img/tex2.png"), textures[2] );
    gl->loadTexture( QString::fromStdWString(L"./img/tex3.png"), textures[3] );
    gl->loadTexture( QString::fromStdWString(L"./img/mask.png"), textures[4] );
}
void CBackgroundScreen::unload(CGraphics *gl)
{
    gl->deleteTexture( textures[0] );
    gl->deleteTexture( textures[1] );
    gl->deleteTexture( textures[2] );
    gl->deleteTexture( textures[3] );
    gl->deleteTexture( textures[4] );
}

int CBackgroundScreen::update(CInput *in)
{
    return 0;
}
void CBackgroundScreen::draw(CGraphics *gl)
{    
    glLoadIdentity();
    glColor3f(1.0f, 1.0f, 1.0f );

    glBindTexture(GL_TEXTURE_2D,textures[0]);   // fonas ir stalo šonai
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f,1.0f); glVertex2i( 0, 0 );
        glTexCoord2f(0.0f,0.0f); glVertex2i( 0, 500 );
        glTexCoord2f(1.0f,0.0f); glVertex2i( 700, 500 );
        glTexCoord2f(1.0f,1.0f); glVertex2i( 700, 0 );
    glEnd();

    glBindTexture(GL_TEXTURE_2D,textures[1]);   // stalas
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f,1.0f); glVertex2i( 47, 68 );
        glTexCoord2f(0.0f,0.0f); glVertex2i( 47, 382 );
        glTexCoord2f(1.0f,0.0f); glVertex2i( 651, 382 );
        glTexCoord2f(1.0f,1.0f); glVertex2i( 651, 68 );
    glEnd();

    glColor3f(1.0f, 1.0f, 1.0f );
    glBindTexture(GL_TEXTURE_2D,textures[2]);   // Stalo vidinės sienos
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f,1.0f); glVertex2i( 62, 68 );
        glTexCoord2f(0.0f,0.0f); glVertex2i( 62, 87 );
        glTexCoord2f(1.0f,0.0f); glVertex2i( 340, 87 );
        glTexCoord2f(1.0f,1.0f); glVertex2i( 340, 68 );

        glTexCoord2f(1.0f,1.0f); glVertex2i( 357, 68 );
        glTexCoord2f(1.0f,0.0f); glVertex2i( 357, 87 );
        glTexCoord2f(0.0f,0.0f); glVertex2i( 635, 87 );
        glTexCoord2f(0.0f,1.0f); glVertex2i( 635, 68 );

        glTexCoord2f(0.0f,0.0f); glVertex2i( 62, 363 );
        glTexCoord2f(0.0f,1.0f); glVertex2i( 62, 382 );
        glTexCoord2f(1.0f,1.0f); glVertex2i( 340, 382 );
        glTexCoord2f(1.0f,0.0f); glVertex2i( 340, 363 );

        glTexCoord2f(1.0f,0.0f); glVertex2i( 357, 363 );
        glTexCoord2f(1.0f,1.0f); glVertex2i( 357, 382 );
        glTexCoord2f(0.0f,1.0f); glVertex2i( 635, 382 );
        glTexCoord2f(0.0f,0.0f); glVertex2i( 635, 363 );
    glEnd();

    glBindTexture(GL_TEXTURE_2D,textures[3]); // stalo vidines sienelės
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f,1.0f); glVertex2i( 47, 84 );
        glTexCoord2f(0.0f,0.0f); glVertex2i( 47, 366 );
        glTexCoord2f(1.0f,0.0f); glVertex2i( 66, 366 );
        glTexCoord2f(1.0f,1.0f); glVertex2i( 66, 84 );

        glTexCoord2f(1.0f,1.0f); glVertex2i( 632, 84 );
        glTexCoord2f(1.0f,0.0f); glVertex2i( 632, 366 );
        glTexCoord2f(0.0f,0.0f); glVertex2i( 651, 366 );
        glTexCoord2f(0.0f,1.0f); glVertex2i( 651, 84 );
    glEnd();

    glDisable(GL_TEXTURE_2D);       // piešiamas pusiau permatomas juodas ekranas
    glColor4f(0.0f, 0.0f, 0.0f, 0.5f );
    glBegin(GL_QUADS);  // fonas
        glVertex2i( 0, 0 );
        glVertex2i( 0, 500 );
        glVertex2i( 700, 500 );
        glVertex2i( 700, 0 );
    glEnd();
    glEnable(GL_TEXTURE_2D);
}
